package com.zoffy.zoffyapi.controller;

import com.zoffy.zoffyapi.commen.BaseResponse;
import com.zoffy.zoffyapi.commen.IdRequest;
import com.zoffy.zoffyapi.commen.ResultUtils;
import com.zoffy.zoffyapi.model.dto.userInterfaceIngo.InvokeInterfaceRequest;
import com.zoffy.zoffyapi.model.vo.UserInterfaceVo;
import com.zoffy.zoffyapi.service.UserInterfaceInfoService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/userInterface")
public class UserInterfaceController {
    @Resource
    private UserInterfaceInfoService userInterfaceInfoService;
    @PostMapping("/grant")
    public BaseResponse<Boolean> grantInterface(HttpServletRequest request, @RequestBody IdRequest idRequest){
        boolean flag = userInterfaceInfoService.grantInterface(request, idRequest);
        return ResultUtils.success(flag);
    }
    @GetMapping("/list")
    public BaseResponse<List<UserInterfaceVo>> listUserInterface(HttpServletRequest request){
        List<UserInterfaceVo> userInterfaceVos = userInterfaceInfoService.listUserInterface(request);
        return ResultUtils.success(userInterfaceVos);
    }
    @PostMapping("/invoke")
    public BaseResponse<String> invokeInterface(HttpServletRequest request,@RequestBody InvokeInterfaceRequest invokeInterfaceRequest) {
        String res = userInterfaceInfoService.invokeInterface(request, invokeInterfaceRequest);
        return ResultUtils.success(res);
    }
}
